<!DOCTYPE html>
<html>
<head>
    <title>简历爬虫系统</title>
    <style>
        body {
            font-family: Arial, sans-serif;
            max-width: 1200px;
            margin: 0 auto;
            padding: 20px;
        }
        .container {
            display: flex;
            gap: 20px;
        }
        .input-area {
            flex: 1;
        }
        .preview-area {
            flex: 2;
        }
        textarea {
            width: 100%;
            height: 100px;
            margin-bottom: 10px;
        }
        button {
            padding: 8px 15px;
            background: #4CAF50;
            color: white;
            border: none;
            cursor: pointer;
            margin-right: 10px;
        }
        button.reset {
            background: #f44336;
        }
        iframe {
            width: 100%;
            height: 600px;
            border: 1px solid #ddd;
            margin-top: 15px;
        }
        .info-box {
            background: #f9f9f9;
            padding: 15px;
            margin-bottom: 15px;
            border-radius: 5px;
        }
        .text-preview {
            max-height: 200px;
            overflow-y: auto;
            padding: 10px;
            background: #f5f5f5;
            border: 1px solid #ddd;
        }
    </style>
</head>
<body>
    <h1>简历爬虫系统</h1>
    
    <div class="container">
        <div class="input-area">
            <form id="crawlForm">
                <h3>输入目标URL或IP地址</h3>
                <textarea name="url" placeholder="例如: 112.74.56.2 或 example.com"></textarea>
                <div>
                    <button type="submit">抓取页面</button>
                    <button type="button" class="reset" onclick="resetData()">重置数据</button>
                </div>
            </form>
            
            <div class="info-box">
                <h3>使用说明</h3>
                <p>1. 支持输入IP地址(如 112.74.56.2)或域名(如 example.com)</p>
                <p>2. 系统会自动尝试HTTP协议</p>
                <p>3. 点击"抓取页面"开始获取目标网页</p>
            </div>
        </div>
        
        <div class="preview-area">
            {% if is_crawled %}
                <h2>{{ resume.title }}</h2>
                <p>来源: <a href="{{ resume.source_url }}" target="_blank">{{ resume.source_url }}</a></p>
                
                <h3>网页预览</h3>
                <iframe srcdoc="{{ resume.content }}"></iframe>
                
                <h3>文本预览</h3>
                <div class="text-preview">{{ resume.text_content }}</div>
                
                <p>
                    <a href="{{ url_for('serve_webpage', filename=resume.saved_path.split('/')[-1]) }}" target="_blank">
                        <button>下载完整网页</button>
                    </a>
                </p>
            {% else %}
                <h2>我的简历</h2>
                <!-- 这里显示您的原始简历内容 -->
                <div class="info-box">
                    <p>姓名: {{ resume.basic_info.name }}</p>
                    <p>职位: {{ resume.basic_info.job_intention }}</p>
                
                    <!-- 其他简历字段 -->
                </div>
            {% endif %}
        </div>
    </div>

    <script>
        document.getElementById('crawlForm').addEventListener('submit', async (e) => {
            e.preventDefault();
            const formData = new FormData(e.target);
            
            const response = await fetch('/crawl', {
                method: 'POST',
                body: new URLSearchParams(formData)
            });
            
            const data = await response.json();
            if (data.success) {
                window.location.href = data.redirect;
            } else {
                alert(data.error || '抓取失败');
            }
        });
        
        function resetData() {
            fetch('/reset', { method: 'POST' })
                .then(() => window.location.href = '/');
        }
    </script>
</body>
</html>